<template>
  <div class="content-box">
    <nav-title title="银行账号信息" />
    <edit-option-line label="开户银行名称" :important="true" :vals="bankVal" v-model="bank.bankCd"></edit-option-line>
    <edit-line label="分/支行" v-model="bank.rsBranchNm"></edit-line>
    <edit-line label="银行账号" :important="true" v-model="bank.accountEcId"></edit-line>
    <edit-line label="账户名称" :important="true" :editting="false" v-model="bank.accountName"></edit-line>
    <div class="bsbtn" @click="save">
      保存
    </div>
  </div>

</template>

<script>
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { getDicItem,saveBank,getBank,getQrmsg } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine, EditOptionLine
  },
  mounted(){
    //获取字典
    this.getBanklb()
    this.bank.rsHireId = this.$store.state.hid
    this.bank.accountName = this.$store.state.name
  },
  data() {
    return {
      bank:{
        rsHireId: '',
      },
      bankVal:[],
    }
  },
  created() {
    this.getBanks()
  },
  methods: {

    //银行
    getBanklb() {
      getBank().then(res => {
        res.retData.forEach((val) => {
          this.bankVal.push({value: val.descrshort, key: val.bankCd})
        });
      })
    },


    save() {
      if(!CommonUtil.valid(this, this.bank,"bankCd","请选择银行名称") 
        || !CommonUtil.valid(this, this.bank,"accountEcId","请输入银行账号")  
        // || !CommonUtil.valid(this, this.bank,"accountName","请输入账户名称")  
        ){
        return;
      }
      saveBank(json2Form(this.bank)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })
        }

        }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    getBanks() {
      if(this.$route.params.banklt){
        this.bank = this.$route.params.banklt
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
  @import "./editinfo";
</style>
